from database import *

def create(session):
    #populate tables:
    if not session.query(User).filter_by(login ='sors').count():
        sors = User(login='sors', pwd_md5='asdf2')
        drak = Creature(name='drakonian', char='@', sight = 6, size = 1)
        sors.creatures = [drak]
        session.add(sors)
        
    if not session.query(User).filter_by(login = 'demoth').count():
        demoth = User(login='demoth', pwd_md5 = 'asdf')
        kob = Creature(name='kobold', char = '@')
        mer = Creature(name='merfolk', char = '&', size = 2)
        demoth.creatures = [kob, mer]
        session.add(demoth)

    if not session.query(Location).filter_by(name ='cave').filter_by(id = 1).count():
        cave = Location(name = 'cave', id = 1)
        cells = []
        map = open('maps/1.map').read()
        for y, line in enumerate(map.split('\n')):
            for x, symb in enumerate(line):
                c = Cell(char = symb, coords = (x,y))
                cells.append(c)
        cave.cells = {c.coords:c for c in cells}
        session.add(cave)
        
    if not session.query(Weapon).filter_by(name='sword').count():
        t = WeaponTemplate()
        t.name = 'sword'
        t.min_damage = 1
        t.max_damage = 3
        t.model = 'sword'
        session.add(t)
        sw = Weapon(t)
        sw.char='|'
        sw.cell = session.query(Location).first().cells[(3,3)]
        session.add(sw)
                
    session.commit()
    

